<?php
/**
 * 在模板中可以用到的一些方法
 * Wiki: http://192.168.0.6:8888/_wiki/doku.php?id=ujn#模板预置方法
 */

function ___P($txt) {
	echo $txt;
}

function ___ECHO($array, $index, $default_value = '') {
	echo ( is_array($array) && isset($array[$index]) ) ? $array[$index] : $default_value;
}

function ___INCLUDE($path, $params = array()) {
	
	switch(true) {
		case ( $f = $path ) != '' && is_file($f):
		case ( $f = ujn::getCFG('templates_path') . $path ) != '' && is_file($f):
			
			$controller_object = ujn_runtime::getParam('controller_object');
			if(false != $controller_object)
				$params = array_merge($controller_object->getViewVars(), $params);
			
			foreach($params as $name => $var) {
				${$name} = $var;
			}
			include $f;
			
			break;
		default:
			echo '<h1>unfound template file ' . $f . '</h1>';
	}
}